package com.qingzhuge.exception;

import java.util.Objects;

/**
 * @author : zero.xiao
 * @description :
 * @date : 2018/8/8 0008 上午 9:29
 * @modified :
 * @since :
 */
public class ServiceException extends BaseException {
    private static final long serialVersionUID = 5455631218932014796L;
    private String msg = "系统繁忙，请稍后再试";
    private int code = 500;

    public ServiceException() {
    }

    public ServiceException(String msg) {
        super(msg);
        this.msg = msg;
    }

    public ServiceException(String msg, Throwable e) {
        super(msg, e);
        this.msg = msg;
    }

    public ServiceException(String msg, int code) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }

    public ServiceException(String msg, int code, Throwable e) {
        super(msg, e);
        this.msg = msg;
        this.code = code;
    }


    public ServiceException(Throwable ex) {
        super(ex);
        this.msg = ex.getMessage();
    }


    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        if (null != this.msg && !Objects.equals("",this.msg)){
            return this.msg;
        }else {
            return super.getMessage();
        }
    }
}
